//
//  ContactUsViewController.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/12/16.
//

#import "ContactUsViewController.h"
#import "WechatCodeViewController.h"

@interface ContactUsViewController ()
@property(nonatomic,strong)UILabel *rightLabel;
@end

@implementation ContactUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
}

-(void)createUI{
    
    [self.customNavigationBar setTitle:@"联系我们"];
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 10;
    bgView.layer.masksToBounds = YES;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@16);
        make.right.mas_equalTo(@-16);
        make.top.mas_equalTo(kYM_NAVIGATIONBAR_HEIGHT+20);
        if(isIPAD){
            make.height.mas_equalTo(@179);
        }else{
            make.height.mas_equalTo(kWFit(179));
        }
    }];
    __weak typeof(self)self_weak_ = self;
    NSArray *arr = @[@"微信",@"小红书",@"邮箱"];
    for(NSInteger i = 0;i < arr.count;i++){
        UIView *bView = [[UIView alloc]initWithFrame:CGRectMake(0,i*kWFit(63), kScreenWidth-32,kWFit(53))];
        if(isIPAD){
            bView.frame = CGRectMake(0,i*63,self.currentAvailableWidth-32,53);
        }
        bView.tag = 100+i;
        [bgView addSubview:bView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            if(i == 0){
                [self_weak_ jumpToWechat];
            }else if (i == 1){
                [self_weak_ jumpToRedBook];
            }else if (i == 2){
                [UIPasteboard generalPasteboard].string = @"1352779004@qq.com";
                [JPProgressHUD showMsg:@"邮箱复制成功"];
            }
        }];
        [bView addGestureRecognizer:tap];
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = JPUIFontPingFangSCMedium(15);
        titleLabel.textColor = KFontBlackColor;
        titleLabel.text = arr[i];
        titleLabel.userInteractionEnabled = YES;
        [bView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(@16);
            make.height.mas_equalTo(@21);
            make.centerY.mas_equalTo(bView);
        }];
        UIImageView *arrowImageView = [[UIImageView alloc]init];
        arrowImageView.image = [UIImage imageNamed:@"mine_right_arrow"];
        arrowImageView.userInteractionEnabled = YES;
        arrowImageView.tag = 200+i;
        [bView addSubview:arrowImageView];
        [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(@-12);
            make.width.height.mas_equalTo(@16);
            make.centerY.mas_equalTo(bView);
        }];
        if (i == 2){
            UILabel *rightLabel = [[UILabel alloc]init];
            rightLabel.font = JPUIFontPingFangSCRegular(14);
            rightLabel.textColor = KFontGrayColor;
            rightLabel.textAlignment = NSTextAlignmentRight;
            rightLabel.text = @"1352779004@qq.com";
            [bView addSubview:rightLabel];
            [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(@-38);
                make.height.mas_equalTo(@21);
                make.centerY.mas_equalTo(bView);
            }];
            self.rightLabel = rightLabel;
        }
        
    }
}

#pragma mark - 跳转小红书
-(void)jumpToRedBook{
    
    NSString *urlString = [NSString stringWithFormat:@"xhsdiscover://user/%@",@"626610660000000010009fc1"];
    NSURL *url = [NSURL URLWithString:urlString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
    }else{
        // 小红书未安装，提示下载
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://apps.apple.com/cn/app/小红书/id741292507"] options:@{} completionHandler:nil];
    }
    
}

#pragma mark - 跳转微信二维码页面
-(void)jumpToWechat{
    WechatCodeViewController *vc = [[WechatCodeViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 屏幕宽度改变
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    if(isIPAD){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 获取当前可用宽度并更新布局
        self.currentAvailableWidth = [DeviceUtils currentAvailableWidth];
        self.currentAvailableHeight = [DeviceUtils currentAvailableHeight];
        self.customNavigationBar.frame = CGRectMake(0, 0, self.currentAvailableWidth,kYM_NAVIGATIONBAR_HEIGHT);
        for(NSInteger i = 0;i < 3;i++){
            UIView *bView = [self.view viewWithTag:100+i];
            bView.frame = CGRectMake(0,i*63,self.currentAvailableWidth-32,53);
            UIImageView *arrowImageView = [bView viewWithTag:200+i];
            [arrowImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(@-12);
                make.centerY.mas_equalTo(bView);
            }];
            if (i == 2){
                [self.rightLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(@-38);
                    make.centerY.mas_equalTo(bView);
                }];
            }
        }
           
        });
    }
}


@end
